package net.xo68.coordinator.core.rpc;

import net.xo68.coordinator.core.rpc.impl.ProtostuffObjectSerializeImpl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 对象序列化工厂
 * @author wuxie
 * @version 2020-9-29
 */
public final class ObjectSerializeFactory {

    public final static String DEFAULT_SERIAL_KEY="ProtostuffObjectSerializeImpl";

    private static final ConcurrentMap<String,ObjectSerialize> objectSerializeMap = new ConcurrentHashMap<>();

    static {
        addObjectSerialize(DEFAULT_SERIAL_KEY, new ProtostuffObjectSerializeImpl());
    }

    public static void addObjectSerialize(String key,ObjectSerialize objectSerialize){
        objectSerializeMap.putIfAbsent(key,objectSerialize);
    }

    public static ObjectSerialize get(){
        return objectSerializeMap.get(DEFAULT_SERIAL_KEY);
    }
    public static ObjectSerialize get(String key){
        return objectSerializeMap.get(key);
    }

}
